using SharpDX;
using SharpDX.Direct3D11;
using System;
using WorldRacing2.Material;

namespace Engine.Graphics.Shaders.Wr2Shaders
{
    public class Material000 : ShaderbaseWr2, ISetShaderValues
    {
        #region Private Fields

        private string name;
        private SamplerState samplerState;
        private SamplerStateDescription samplerStateDescription;

        #endregion Private Fields

        #region Public Constructors

        public Material000(Device renderDevice, string shaderDirectory, ShaderManager shaderManager)
            : base(renderDevice, shaderManager)
        {
            //shaderDirectory = shaderDirectory.Replace("WorldRacing2\\", "");
            this.name = shaderDirectory;
            base.LoadShader(renderDevice, shaderDirectory + "\\material00.fx", "ps_main", "vs_main");
            this.inputLayout = new InputLayout(renderDevice, this.shaderByteCodeVS, Graphics.VertexStructures.Wr2VertexElements.elements);

            // Create samplerstate
            this.samplerStateDescription = new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = new Color4(0),
                ComparisonFunction = Comparison.Always,
                Filter = Filter.Anisotropic,
                MaximumAnisotropy = 16,
                MaximumLod = float.MaxValue,
                MinimumLod = 0,
                MipLodBias = 0
            };

            this.samplerState = new SamplerState(renderDevice, this.samplerStateDescription);
        }

        #endregion Public Constructors

        #region Public Properties

        public ShaderBase Effect
        {
            get
            {
                return this.effect;
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion Public Properties

        #region Public Methods

        public new void Dispose()
        {
            this.ps.Dispose();
            this.inputLayout.Dispose();
            this.vs.Dispose();
            this.samplerState.Dispose();
            base.Dispose();
        }

        public void SetProperties(int materialID, MaterialManager materialManager)
        {
            Wr2Material material = (Wr2Material)materialManager.GetMaterialForGame(materialID);
            base.SetSamplerState(this.samplerState, 0);
            base.SetSamplerState(this.samplerState, 1);
            base.SetSamplerState(this.samplerState, 2);

            ShaderBase.SetTexture(0, materialManager.Textures[material.TextureID1], base.Device);
            ShaderBase.SetTexture(1, materialManager.Textures[material.TextureID2], base.Device);
            ShaderBase.SetTexture(2, materialManager.Textures[material.TextureID3], base.Device);

            base.SetUvMatrix1(material);
            base.SetUvMatrix2(material);
            base.SetUvMatrix3(material);
        }

        #endregion Public Methods
    }
}